/*#################################################

Canopy | v1.4 
Max Felker | max@bigroomstudios.com

Creates an overlay

#################################################*/
 
// START Class
var Canopy = Class.create({

	initialize: function() { },

	create: function() {
		
		if($('canopy')){ 

			return false;
			
		} else {
		
			live.body.setStyle('position:relative;');

			var overlay = Builder.node('div', { id: 'canopy', style: 'display:none;'},[
				 Builder.node('div', { id: 'canopy-overlay'}),
				 Builder.node('div', { id: 'canopy-btn-close'})
			]);
	
			live.body.appendChild(overlay);
			
			this.container = $('canopy');
			this.overlay = $('canopy-overlay');
			this.btn_close = $('canopy-btn-close');
			
			this.overlay.setOpacity(0.7);
			this.btn_close.on('click',this.close.bind(this));
			
			live.keys.look_for('esc',live.canopy.close);
   			
   			this.active = false;
			
		}
		
	},

	display: function(config) {
	
		if(!$('canopy')){ 
		
			this.create();
			
		}
		
		clearTimeout(this.timeout);

		if(!this.active){

			this.timeout = setTimeout(function(){

				this.active = true;
		     	new Effect.Appear(this.container, { duration: 0.25 });

			}.bind(this),250);
               
		}
		
	},

	close: function() {
	
		clearTimeout(this.timeout);

		if(this.active){

			this.timeout = setTimeout(function(){
			
				live.html.setStyle({
					overflow: 'auto',
					width:'auto'
				});
		
				live.body.setStyle({
					height: 'auto'
				});

		     	new Effect.Fade(this.container, { duration: 0.25 });
				this.btn_close.stopObserving('click',this.close.bind(this));
				
				this.active = false;

			}.bind(this),250);
               
		}

	},


	remove: function() {

		if($('canopy')){ 
			this.off();
			live.body.removeChild(this.container);
		} else {
			alert("Canopy doesn't exsist!");	
			return false;
		}	
					 
	}

}); // END Class
